<template>
  <div class="usr">
    <dv-border-box-7 style="width: 95%; height: 80px; margin-top: 30px">
      <div ref="chart" style="width: 100%; height: 80px"></div>
    </dv-border-box-7>
  </div>
</template>

<script>
import * as echarts from "echarts";
import { mapState } from "vuex";

export default {
  name: "RectangleChart",
  data() {
    return {
    };
  },
  computed: mapState({
    members: function (state) {
      return state.data.crmData.members.totalCount;
    },
    newMembers: function (state) {
      return state.data.crmData.newMembers.totalCount;
    },
  }),
  mounted() {
    this.initChart();
  },
  methods: {
    initChart() {
      const chart = echarts.init(this.$refs.chart);

      const option = {
        graphic: [
          // 绘制竖线分割
          {
            type: "line",
            shape: {
              x1: "50%",
              y1: "0%",
              x2: "50%",
              y2: "100%",
            },
            style: {
              stroke: "#839AAC",
              lineWidth: 2,
            },
          },
          // 左上角的数据（值在上，name在下）
          {
            type: "text",
            left: "8%",
            top: "15%",
            style: {
              text: `今日新增`, // 显示名称
              font: "16px Arial",
              fill: "#839AAC", // 设置名称的颜色
            },
          },
          {
            type: "text",
            left: "8%",
            bottom: "15%",
            style: {
              text: `${this.newMembers}`, // 显示值
              font: "bold 30px Arial",
              fill: "#1A4F79", // 设置值的颜色
            },
          },
          // 右上角的数据
          {
            type: "text",
            right: "8%",
            top: "15%",
            style: {
              text: `会员总计`,
              font: "16px Arial",
              fill: "#839AAC", // 设置名称的颜色
            },
          },
          {
            type: "text",
            right: "8%",
            bottom: "15%",
            style: {
              text: `${this.members}`,
              font: "bold 30px Arial",
              fill: "#A8AFB9",
            },
          },
        ],
      };

      chart.setOption(option);
    },
  },
};
</script>

<style scoped>
/* 如果需要，可以添加自定义的样式 */
.usr {
  width: 100%;
  height: 300px;
  background-image: url("../../assets/img/bg_line2.svg");
  background-size: 100% 100%; /* 设置背景图宽度和高度为100% */
  background-position: center center; /* 设置背景图居中显示 */
  background-repeat: no-repeat; /* 防止背景图重复 */
  display: inline-block;  /* 容器不会因图表内容而改变大小 */
  position: relative; /* 设置相对定位 */
  box-sizing: border-box;
}
</style>
